# -*- coding: utf-8 -*-
# File : nmap_discovery_call.py
# Author: taoyahui
# Date : 2021/7/16
import requests
from application_factory.extensions import scheduler
from utils import mysql_util
import results


def cal_service():
    query_sql = "SELECT time_interval from inventory_discovery"
    res = mysql_util.exec_sql_new(query_sql)
    if len(res) == 0:
        return results.server_error_result
    time_interval = int(res[0][0])
    # call_discovery_task()
    scheduler.add_job(func=call_discovery_task, id="call-discovery-immediately")
    job = scheduler.add_job(func=call_discovery_task,
                            id=f"唤醒资产发现功能-call_task",
                            trigger='interval',
                            seconds=time_interval,
                            replace_existing=True
                            )

    return results.success_result


def call_discovery_task():
    res = requests.post("http://localhost:5002/inventory_discovery")
    print(res.json())


if __name__ == '__main__':
    call_discovery_task()
